<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2023 yoncron All rights reserved.
// +----------------------------------------------------------------------
// | Author: yoncron <yoncron@163.com>
// +----------------------------------------------------------------------
namespace app\controller\app\im;

use app\controller\app\AppBase;
use app\model\FriendsModel;
use app\model\UserModel;
use app\service\Route;

class Profile extends AppBase
{
    /**
     * description:个人资料
     * @Route(reqUrl="/im.profile.info")
     * author:yoncron<yoncron@163.com>
     * data:2023/11/05
     */
    public function info(){
        if(input('uid',null)===null){
            return error(1,'查询条件未知');
        }
        $where=[];
        $where[] = ['user_id','=',input('uid')];
        $userObj = new UserModel();
        $user = $userObj->field('user_id,usercode,mobile,username,avatar,sex,online_status,username as show_name')->where($where)->find();
        if($user){
            $friendsObj = new FriendsModel();
            $friend = $friendsObj->where([['mine_user_id','=',$this->user_id],['friend_user_id','=',$user['user_id']]])->find();
            if($friend){
                $user['is_friend']=1;
                if($friend['remark']){
                    $user['show_name'] = $friend['remark'];
                }
            }
            else{
                $user['is_friend']=0;
            }
        }
        return success($user);
    }
}